
/**
 * Jun 3, 2010
 * Jiadong Zhu
 * jiadong.zhu@exigenservices.com
 */

package taihootech.qa.th.loader;

import java.io.File;

import org.apache.commons.configuration.*;

public class XMLLoader extends Loader {
	
	protected final static String EXT = ".xml"; 
	private String suite = null;
	private String excluded = null;

	public XMLLoader(ISuiteLoader iloader) {
		super(iloader);
		this.iloader = iloader;
	}///:~
	
	@Override
	public void runSuite(Object obj) {
		File xml = null;
		XMLConfiguration config = null;
		if(isXML(obj)) {
			xml = new File(obj.toString());
			try {
				config = new XMLConfiguration(xml);
				suite = config.getString(PropertyLoader.SUITE, PropertyLoader.DEFAULT);
				excluded = config.getString(PropertyLoader.EXCLUDED);
			}  catch (Exception e) {
	            e.printStackTrace();
	        }
		}
		this.iloader.runSuite(suite);
	}///:~
	
	private boolean isXML(Object obj) {
		boolean isXML = false;
		if (obj instanceof String) {
			String path = obj.toString();
			isXML = path.endsWith(XMLLoader.EXT);
		}
		return isXML;
	}///:~

}///:~ XMLLoader Ends


